package com.tuniondata.netty.server;

import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author yuxinchao
 * netty 链接通道过期策略
 */
public class NettyChannelMap {
    private static ConcurrentHashMap<String,SocketChannel> map = new ConcurrentHashMap<String, SocketChannel>(1024);

    public static void add(String clientId, SocketChannel socketChannel){
        map.put(clientId, socketChannel);
    }

    public static Channel get(String clientId){
       return map.get(clientId);
    }
    public static void remove(SocketChannel socketChannel){
        for (Map.Entry entry : map.entrySet()){
            if (entry.getValue() == socketChannel){
                map.remove(entry.getKey());
            }
        }
    }
}
